package com.afkt.app.slice;

import com.afkt.app.ResourceTable;
import com.afkt.app.utils.GetInfoUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Text;

public class ScreenInfoAbilitySlice extends AbilitySlice {

    private Text screenWidth;
    private Text screenHeight;
    //分辨率
    private Text screenResolution;
    //x轴DPI
    private Text screenXdpi;
    //y轴DPI
    private Text screenYdpi;
    //密度
    private Text screenDensity;
    //屏幕DPI密度
    private Text screenDensityDpi;
    //缩放密度
    private Text scaledDensity;
    //高度基准DPI
    private Text screenHeightDpi;
    //宽度基准DPI
    private Text screenWidthDpi;
    //转换DPI
    private Text screenTransformDpi;


    private Button goBack;


    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_screen_info);


        /**
         *设置返回
         * */
        goBack =(Button) findComponentById(ResourceTable.Id_btn_back_screen);
        if(goBack!=null){
            goBack.setClickedListener(component -> {
                present(new MainAbilitySlice(), new Intent());
            });
        }

      /**
       * 设置屏幕宽度
       * */
        screenWidth = (Text) findComponentById(ResourceTable.Id_screen_width);
        screenWidth.setText(Integer.toString(GetInfoUtils.getDisplayWidthInPx(getContext())));

        /**
         * 设置屏幕高度
         * */
        screenHeight = (Text) findComponentById(ResourceTable.Id_screen_height);
        screenHeight.setText(Integer.toString(GetInfoUtils.getheight(getContext())));

        /**
         * 设置屏幕分辨率
         * */
        screenResolution = (Text) findComponentById(ResourceTable.Id_screen_resolution);
        String resolution =  Integer.toString(GetInfoUtils.getheight(getContext()))+"x"+Integer.toString(GetInfoUtils.getDisplayWidthInPx(getContext()));
        screenResolution.setText(resolution);

        /**
         * 设置X轴DPI
         * */
        screenXdpi = (Text) findComponentById(ResourceTable.Id_screen_xdpi);
        screenXdpi.setText(Integer.toString(GetInfoUtils.getScreenXDpi(getContext())));


        /**
         * 设置Y轴DPI
         * */
        screenYdpi = (Text) findComponentById(ResourceTable.Id_screen_ydpi);
        screenYdpi.setText(Integer.toString(GetInfoUtils.getScreenYDpi(getContext())));


        /**
         * 设置密度
         * */
        screenDensity = (Text) findComponentById(ResourceTable.Id_screen_density);
        screenDensity.setText(Integer.toString(GetInfoUtils.getDensityPixels(getContext())));


        /**
         * 设置DPI密度
         * */
        screenDensityDpi = (Text) findComponentById(ResourceTable.Id_screen_densityDpi);
        screenDensityDpi.setText(Integer.toString(GetInfoUtils.getDensityDpi(getContext())));


        /**
         * 设置缩放密度
         * */
        scaledDensity = (Text) findComponentById(ResourceTable.Id_screen_scaledDensity);
        scaledDensity.setText(Integer.toString(GetInfoUtils.getScalDensity(getContext())));


    }


    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
